package com.mx.kn.cstf2.actions.crud.transition;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import kn.cstf2.transition.Bean.PersonalBean;
import kn.cstf2.transition.Bean.TransitionBean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.mx.kn.cstf2.dts.PersonOptions;
import com.mx.kn.cstf2.service.TransitionService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Component("listPersonalPersonOptionAction")
@Scope(value="session")
public class ListPersonalPersonOptionAction extends ActionSupport{
	private String result;
	private List<PersonOptions> options = new ArrayList<PersonOptions>();

	@Autowired private TransitionService transitionService; 

	public String list() {
		
		
		ActionContext contexto = ActionContext.getContext();
        Map<String, Object> sesion2 = contexto.getSession();
        
        try {
			
			if (options.size() > 0)
				options.clear();
			
			options = transitionService.getPersonalAdd(((TransitionBean)sesion2.get("Knkey"))) ;
			PersonOptions defaultPerson = new PersonOptions();
			defaultPerson.setDisplayText("Select person");
			defaultPerson.setValue("0");
			options.set(0, defaultPerson);

			result = "OK";
			return SUCCESS;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}catch(NullPointerException npe){
			return ERROR;
		}
        		
		
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public List<PersonOptions> getOptions() {
		return options;
	}

	public void setOptions(List<PersonOptions> options) {
		this.options = options;
	}
	
	



	
}
